<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>订单列表</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" type="text/css" href="css/main.css" />
  <link rel="stylesheet" type="text/css" href="../mobile/js/layer/css/layui.css" />
  <script src="../mobile/js/jquery-1.9.1.js"></script>
  <script src="../mobile/js/layer/layui.js"></script>
  <script src="./js/common.js"></script>
  <script type="text/javascript">
      //访问是否登录,ajax同步请求
      logins(); 
  </script>
</head>
<body>
<div style="margin: -30px 20px 20px 20px;">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  <legend>订单列表</legend>
</fieldset>
<blockquote class="layui-elem-quote">
        <div class="layui-inline">
            <input class="layui-input" name="key" id="key" placeholder="请输入订单号">
        </div>&nbsp;
	   <button class="layui-btn btns" id="search" data-type="reload"><i class="layui-icon" style="color: #fff">&#xe615;</i>搜索</button>
	   <button class="layui-btn" style="border: 1px solid #35C4F9;background: none;color:#35C4F9" id="daochu"><i class="layui-icon" style="color: #35C4F9">&#xe641;</i>导出订单</button>
	   <span class="layui-form" style="display: inline-block;">
	   <select name="paystates" id="paystates" lay-filter="paystates">
		   	<option>支付状态</option>
		    <option value="1">已支付</option>
		    <option value="0">未支付</option>
	   </select>
	   </span>
	   <button class="layui-btn btns_del" id="delAll"><i class="layui-icon" style="color: #fff">&#xe640;</i>批量删除</button>
</blockquote>
<table class="layui-hide" id="list" lay-filter="list"></table>
</div>
<script type="text/html" id="paystate">
    {{# if(d.paystate==1){ }}
       <span style="color: #35C4F9">已支付</span>
    {{# }else{  }}
       <span style="color: red">未支付</span>
    {{# } }}
</script>
<script type="text/html" id="action">
    <a href="order_detail.html?orderid={{d.orderid}}" title="查看详情"><i class="layui-icon" style="color: #5FB878;font-size: 25px;">&#xe642;</i></a>
    <a lay-event="del" title="删除"><i class="layui-icon" style="color:#FF5722;font-size: 25px;">&#xe640;</i></a>
</script>
<script>
layui.use(['table','form','layer'], function() {
      var table = layui.table,form = layui.form,layer = layui.layer,$ = layui.jquery;
      // var urls = url + "/admin/centerapi/orderListcenter";
      var urls = url + "/admin/order/orderList";
      var tableIn = table.render({
          elem: '#list',
          url: urls,
          method: 'post',
          page: true,
          where: {},
          cols: [[
              {checkbox:true,fixed: true},
              {field: 'orderid', title: '编号', fixed: true,width:100,align: 'center', },
              {field: 'order_on', title: '订单号',width:150,align: 'center',},
              {field: 'nickname', title: '用户',align: 'center',},
              // {field: 'oneDaili', title: '一级代理商',align: 'center', },
              // {field: 'twoDaili', title: '二级代理商',align: 'center', },
              {field: 'device_id', title: '设备号',width:200,align: 'center', },
              {field: 'taocan', title: '套餐',align: 'center', },
              {field: 'order_money', title: '充值金额(元)',align: 'center', },
              {field: 'endtime', title: '结束时间',align: 'center', },
              // {field: 'yongjin_one', title: '一级佣金比例',align: 'center', },
              // {field: 'yongjin_two', title: '二级佣金比例',align: 'center', },
              {title: '支付状态',width:100, align: 'center', toolbar: '#paystate'},
              {title: '操作', width: 100, align: 'center', toolbar: '#action'}
          ]],
          limit: 10, //每页默认显示的数量
          done:function(msg){
             if (msg.codes == 0) {
                layer.alert(msg.infomsg,{time:1000,icon:5});
             }
          }
      });

     /* //修改状态
      form.on('switch(status)', function(obj){
            var urls = "/admin/config/status";
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var id = this.value;
            var status = obj.elem.checked===true?1:0;
            $.post(urls,{'id':id,'status':status},function(msg) {
                  layer.close(loading);
                  var msg = JSON.parse(msg);
                  if(msg.code == 1){
                      layer.msg(msg.infomsg,{time:1000,icon:6});
                      tableIn.reload();
                  }else{
                      layer.msg(msg.infomsg,{time:1000,icon:5});
                  }
            });
      });*/

      form.on('select(paystates)', function(data){
      	 tableIn.reload({
                where: {paystate: data.value}
            });
      })
      
      //单条记录删除
      table.on('tool(list)', function(obj) {
            // var urls = "/admin/centerapi/delordercenter";
            var urls = "/admin/order/delorder";
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('您确定要删除该记录吗？', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post(urls,{orderid:data.orderid},function(msg){
                        layer.close(loading);
                        var msg = JSON.parse(msg);
                        if(msg.code == 1){
                            layer.msg(msg.infomsg,{time:1000,icon:6});
                            tableIn.reload();
                        }else{
                            layer.msg(msg.infomsg,{time:1000,icon:5});
                        }
                    });
                    layer.close(index);
                });
            }
        });

      //批量删除
      $("#delAll").click(function(){
          // var urls = "/admin/centerapi/delallordercenter";
          var urls = "/admin/order/delallorder";
          layer.confirm('确认要删除选中信息吗？',{icon: 3},function(index) {
            layer.close(index);
            var checkStatus = table.checkStatus('list'); //test即为参数id设定的值
            var ids = [];
            $(checkStatus.data).each(function (i, o) {
                ids.push(o.orderid);
            });
            var loading = layer.load(1, {shade: [0.1, '#fff']});
            $.post(urls,{orderid:ids},function(msg){
                layer.close(loading);
                var msg = JSON.parse(msg);
                if (msg.code == 1) {
                    layer.msg(msg.infomsg, {time: 1000, icon: 6});
                    tableIn.reload();
                }else{
                    layer.msg(msg.infomsg, {time: 1000, icon: 5});
                }
            });
          })
      });
       
      //搜索内容
      $('#search').on('click', function() {
            var key = $('#key').val();
            if($.trim(key)==='') {
                layer.msg('请输入关键字！',{icon:0});
                return;
            }
            tableIn.reload({
                where: {key: key}
            });
      });

      //导出订单
      $('#daochu').click(function(){
          var urls = url + "/admin/order/exportorder";
          window.location.href= urls;
      })
});
</script>
</body>
</html>